import React, { Component, PropTypes } from 'react'
import { connect } from 'react-redux'
import { browserHistory } from 'react-router'
import { userLogin } from '../actions/login'

class App extends Component {
  constructor(props) {
    super(props)
  }

  componentDidMount() {
    
  }

  render() {
    const { children } = this.props
    
    return (
      <div>
        {this.props.login.isFetching ? <h1>登录中</h1> : ''}
        Hello World {this.props.login.user.employeeCode}
        {!this.props.login.user.token ? <input type="button" onClick={this.handleLoginBtn.bind(this)} value="登录"/> : ''}
        {children}
      </div>
    )
  }

  handleLoginBtn() {
    this.props.userLogin('dw_chenwenliang', 'Tiankong_2', true)
  }

  loadingSpiner() {
    if (this.props.login.isFetching) return (<h1>登录中</h1>)
  }

}

App.propTypes = {
  children: PropTypes.node
}

function mapStateToProps(state, ownProps) {
  return {
    login: state.login
  }
}

export default connect(mapStateToProps, {
  userLogin
})(App)